﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuxiWTO.Mapping;
using WutiWTO.Common;

namespace WuxiWTO.Web.UserControl
{
    public partial class Search : System.Web.UI.UserControl
    {
        WTODataContext ctx = new WTODataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindParentCategory();
            }
        }

        private void BindParentCategory()
        {
            this.ddlParent.Items.Clear();
            var parent = ctx.categories.Where(p => p.art_parent_kind == 0).ToList();
            foreach (category cat in parent)
            {
                this.ddlParent.Items.Add(new ListItem(cat.art_kind_name, cat.art_kind_id.ToString()));
            }
            this.ddlParent.Items.Insert(0, new ListItem("--请选择--", ""));
        }

        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            string pid = this.ddlParent.SelectedItem.Value;
            string keywords = this.txtKeyWords.Text.Trim();
            Response.Redirect(string.Format("SearchResult.aspx?pid={0}&keywords={1}", pid, Server.HtmlEncode(keywords)));
        }
    }
}